package com.jqweb.pojo;

import lombok.Data;
import lombok.Getter;

@Getter
@Data
public class Result {
    private Integer code;
    private String msg;
    private Object data;
    
    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    
    public <T> Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
    public static Result error (String msg) {
        return new Result(500, msg);
    }
    
    // 警告响应
    public static <T> Result warning (String msg, T data) {
        return new Result(201, msg, data);
    }

    // 成功相应
    public static <T> Result success (String msg, T data) {
        if (data == null) return new Result(200, msg);
        return new Result(200, msg, data);
    }
    
    
}
